package com.example.androidmychapter.util;

import android.media.MediaRecorder;
import android.util.Log;
import android.widget.Toast;


import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class RecordingUtil {
    private static List<String> audioFilePaths = new ArrayList<>();
    private MediaRecorder mediaRecorder;
    private boolean isRecording = false;

    public static List<String> getArryList() {
        return audioFilePaths;
    }

    public void startRecording(String outputFile) {
        mediaRecorder = new MediaRecorder();
        mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
        mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
        mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
        audioFilePaths.add(outputFile);
        mediaRecorder.setOutputFile(outputFile);
        try {
            mediaRecorder.prepare();
            mediaRecorder.start();
            isRecording = true;
        } catch (IOException e) {
            e.printStackTrace();
            Log.e("MediaRecorderError", "prepare() failed: " + e.getMessage());
        }
    }
    public void stopRecording() {
        if (!isRecording) {
            return;
        }
        mediaRecorder.stop();
        mediaRecorder.release();
        mediaRecorder = null;
        isRecording = false;

    }
}
